package com.ymatou.iapi.ocr.testcase;

import java.io.File;
import java.io.IOException;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.zxing.WriterException;
import com.ymatou.iapi.ocr.parameter.ChangeWxUrlStatusBean;
import com.ymatou.iapi.ocr.parameter.WeiXinCheckBean;
import com.ymatou.iapi.ocr.service.ChangeWxUrlStatusCall;
import com.ymatou.iapi.ocr.service.WeiXinCheckCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.sqlwapper.OCRWrapper;
import com.ymttest.utils.TestDataManager;
/**
*更改微信导流检测结果
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ChangeWxUrlStatus{
	private static ChangeWxUrlStatusBean changewxurlstatusBean;
	private static ChangeWxUrlStatusCall changewxurlstatusCall;
	OCRWrapper OCRWrapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("更改微信导流检测结果");
	}

	@Before
	public void caseUp() {
		changewxurlstatusBean=new ChangeWxUrlStatusBean();
		changewxurlstatusCall=new ChangeWxUrlStatusCall();
		OCRWrapper = new OCRWrapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(changewxurlstatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private Map WeixinCheck() throws IOException, WriterException{
		WeiXinCheckBean weixincheckBean=new WeiXinCheckBean();
		WeiXinCheckCall weixincheckCall=new WeiXinCheckCall();
		String fpath = System.getProperty("user.dir") + File.separator
				+ "resource" + File.separator + "noymt.jpg";
		String u="http://u.wechat.com/1.jpg";
		TestDataManager.CreateMatrixFile(u, fpath);
		String turl=TestDataManager.UploadFile(fpath);
		weixincheckBean.setAppId("autotest");
		weixincheckBean.setBizId(TestDataManager.getRandomUUID().toString());
		weixincheckBean.setImgUrl(turl);
		weixincheckBean.setUserId(1);
		weixincheckCall.setData(weixincheckBean);
		weixincheckCall.callService();		
		
		Map info = OCRWrapper.selectTopicWeixinByBizId(weixincheckBean.getBizId()).get(0);
		return info;
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeWxUrlStatus_001() {
		Logger.start(true,"更改微信导流检测结果成功");
		try {
			Map  m=WeixinCheck();
			Logger.debug(m);
			changewxurlstatusBean.setWxUrlId((int)m.get("Id"));
			changewxurlstatusBean.setWxUrlStatus(0);
			changewxurlstatusCall.setData(changewxurlstatusBean);
			changewxurlstatusCall.callService();
			Logger.verifyEquals("200", changewxurlstatusCall.getString("Status"), "验证Status");
			m=OCRWrapper.selectTopicWeixinByBizId( m.get("BizId").toString()).get(0);
			Logger.verifyEquals(changewxurlstatusBean.getWxUrlStatus(), m.get("CheckStatus"), "验证status");
			changewxurlstatusBean.setWxUrlStatus(1);
			changewxurlstatusCall.callService();
			Logger.verifyEquals("200", changewxurlstatusCall.getString("Status"), "验证Status");
			m=OCRWrapper.selectTopicWeixinByBizId( m.get("BizId").toString()).get(0);
			Logger.verifyEquals(changewxurlstatusBean.getWxUrlStatus(), m.get("CheckStatus"), "验证status");
			changewxurlstatusBean.setWxUrlStatus(2);
			changewxurlstatusCall.callService();
			Logger.verifyEquals("200", changewxurlstatusCall.getString("Status"), "验证Status");
			m=OCRWrapper.selectTopicWeixinByBizId( m.get("BizId").toString()).get(0);
			Logger.verifyEquals(changewxurlstatusBean.getWxUrlStatus(), m.get("CheckStatus"), "验证status");
			changewxurlstatusBean.setWxUrlStatus(3);
			changewxurlstatusCall.callService();
			Logger.verifyEquals("200", changewxurlstatusCall.getString("Status"), "验证Status");
			m=OCRWrapper.selectTopicWeixinByBizId( m.get("BizId").toString()).get(0);
			Logger.verifyEquals(changewxurlstatusBean.getWxUrlStatus(), m.get("CheckStatus"), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeWxUrlStatus_002() {
		Logger.start(true,"不输入id失败");
		try {
//			Map  m=WeixinCheck();
//			Logger.debug(m);
//			changewxurlstatusBean.setWxUrlId((int)m.get("Id"));
			changewxurlstatusBean.setWxUrlStatus(0);
			changewxurlstatusCall.setData(changewxurlstatusBean);
			changewxurlstatusCall.callService();
			Logger.verifyEquals("500", changewxurlstatusCall.getString("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeWxUrlStatus_003() {
		Logger.start(true,"输入无效id失败");
		try {
//			Map  m=WeixinCheck();
//			Logger.debug(m);
			changewxurlstatusBean.setWxUrlId(-100);
			changewxurlstatusBean.setWxUrlStatus(0);
			changewxurlstatusCall.setData(changewxurlstatusBean);
			changewxurlstatusCall.callService();
			Logger.verifyEquals("400", changewxurlstatusCall.getString("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ChangeWxUrlStatus_004() {
		Logger.start(true,"不输入status失败");
		try {
			Map  m=WeixinCheck();
			Logger.debug(m);
			changewxurlstatusBean.setWxUrlId((int)m.get("Id"));
//			changewxurlstatusBean.setWxUrlStatus(0);
			changewxurlstatusCall.setData(changewxurlstatusBean);
			changewxurlstatusCall.callService();
			Logger.verifyEquals("400", changewxurlstatusCall.getString("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}